#!/bin/bash

cat > /etc/modules-load.d/crio.conf << \EOF
overlay
br_netfilter
EOF

cat > /etc/modules-load.d/ipvs.conf << \EOF
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack
ipt_rpfilter
ipip
nf_conntrack_netlink
ip_tables
ip6_tables
ip_set
xt_set
ipt_set
ipt_REJECT
EOF

cat >> /etc/security/limits.conf <<\EOF
*          soft    nproc     65535
*          hard    nproc     65535
root       soft    nproc     unlimited
*          soft    memlock   unlimited
*          hard    memlock   unlimited
EOF

mkdir -p ~/.pip
cat > ~/.pip/pip.conf << \EOF
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
EOF

apt remove nano docker docker-engine docker.io containerd runc -y

apt install \
    apt-transport-https lrzsz apt-transport-https ca-certificates curl gnupg lsb-release software-properties-common \
    python3-pip lsof lrzsz telnet traceroute tcptraceroute net-tools bash-completion vim sshpass mtr lvm2 conntrack \
    ipvsadm ipset jq sysstat iotop iftop htop tree glances fio unzip haproxy -y

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt -y install docker-ce=5:19.03.15~3-0~ubuntu-focal

cat>/etc/docker/daemon.json<<\EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "registry-mirrors": [
    "https://2ph0ua9a.mirror.aliyuncs.com",
    "https://hub-mirror.c.163.com",
    "https://registry.docker-cn.com",
    "https://docker.mirrors.ustc.edu.cn"
  ],
  "graph":"/var/lib/docker",
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m",
    "max-file": "3"
  }
}
EOF

pip3 install -U pip setuptools
pip3 install docker-compose setuptools_rust setuptools cffi launchpadlib --upgrade

systemctl enable --now docker

timedatectl set-timezone Asia/Shanghai
cat > /etc/profile.d/tz.sh << \EOF
export TZ=Asia/Shanghai
EOF
export TZ=Asia/Shanghai

docker pull ethereum/client-go:alltools-v1.10.16
docker pull ethereum/client-go:alltools-v1.9.25
